<template>
  <el-dialog @close="handleClose" title="批量添加线索" :visible.sync="open" append-to-body>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="选择文件" prop="clueFile">
        <el-upload
          ref="upload"
          action="#"
          :auto-upload="false"
          :on-change="changeUpload"
          :limit="1"
          accept=".xls,.xlsx"
        >
          <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
        </el-upload>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="open = false">取 消</el-button>
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { uploadClues } from "@/api/crm/clue";
    export default {
        name: "batch-add",
      data() {
          return {
            open: false,
            form: {
              clueFile: null,
            },
          }
      },
      methods: {
        submitForm() {
          this.$refs['form'].validate(valid => {
            if(valid) {
              uploadClues(this.form).then(resp=>{
                this.$message({
                  message: '恭喜你，批量操作成功',
                  type: 'success'
                });
                this.open = false
                this.$emit('success')
              })
            }
          })
        },
        resetForm() {
          this.form = {
            clueFile: null,
          }

        },
        changeUpload(file) {
          this.form.clueFile = file.raw;
        },
        handleClose() {
          this.$refs.upload.clearFiles();
        }
      },
    }
</script>

<style scoped>

</style>
